
<template>
 <div  class="components-container">
     
    <sweet-modal ref="dialog" class="dialog" v-bind:blocking="true">
      <h3>{{ title }}</h3>
  
      <div style="min-height:200px; margin:30px 50px">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">项目名称</label>
                <div class="layui-input-inline">
                      <el-input v-model="userData.REDNAME" placeholder="请输入项目名称" :disabled="isinfo"></el-input>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">项目类型</label>  
                <div class="layui-input-inline">
                    <el-select v-model="userData.REDTYPE" placeholder="项目类型" :disabled="isinfo">
                        <el-option v-for="item in pointType" :key="item.CodeValue" :label="item.CodeName" :value="item.CodeValue"></el-option>
                    </el-select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">备注</label>
              <div class="layui-input-inline">
                  <el-input type="textarea" v-model="userData.REDREMARKS" class="formWide" style="width:494px;" placeholder="请输入备注" :disabled="isinfo" />
              </div>
            </div>
        </div>
      </div>

      <div class="layui-form-item btnCenter" z-index=100>
          <el-button @click="closeDialog">取消</el-button>
          <el-button v-if="!isinfo" type="primary" @click="submit" :loading="this.$store.state.isloading">确定</el-button>
      </div>
    </sweet-modal>
 </div>
</template>

<script>
import sweetModal from "@/components/sweetModal";
import apiBase from "@/api/apiBase.js";
const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";
export default {
  data() {
    return {
      title: null,
      btnListIfon: [],
      GetSFLY: [],
      pointType: [],//减免类型 接收数组
      isinfo: null,
      ids:null,
      userData: {
        REDNAME: null,  //--  减免项目名称
        REDTYPE: null, // --  减免项目类型
        REDREMARKS: null, // --  备注
      },
      roles:null
      
     }
   },
   methods: {
      //功能操作
      open(order, id) {
        this.order = order;
        this.ids = id;
        this.getPointType();
        this.dataRepeat();
        switch (this.order) {
          case ADD:
            this.userData.REDTYPE="A";
            this.title = "收费项目新增";
            this.isinfo = false;
            this.$refs.dialog.open();
            break;
          case MODIFY:
            this.title = "修改";
            this.isinfo = false;
            this.dataInfo(id);
            this.$refs.dialog.open();
            break;
          case INFO:
            this.title = "详情";
            this.isinfo = true;
            this.dataInfo(id);
            this.$refs.dialog.open();
            break;
          case DELETE:
            this.dataDelete(id);
            break;
          default:
        }
      },
    //获取减免类型
      getPointType() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Code.GetKeyPointType,
          res => {
            this.pointType = res.data.content;    
          }
        );
      },
    //数据重置
    dataRepeat() {
        this.userData = {
        REDNAME:null,    //--  减免项目名称
        REDTYPE:null,       // --  减免项目类型
        REDREMARKS:null,
        };
    },
    //提交
    submit() {
      this.$store.state.isloading = true;
      switch (this.order) {  
        case ADD:
          this.dataAdd();
          break;
        case MODIFY:
          this.dataModify();
          break;
        case DELETE:
          break;
        case INFO:
          this.$refs.dialog.close();
        
          break;
        default:
      }
    },
    //修改
    dataModify() {
      let Data = JSON.parse(JSON.stringify(this.userData));
      Data.REDID = this.ids;
      apiBase.DoService(Data, apiBase.getApiAdress().ChargeProject.UpdateModifyRed, res => {
        this.$refs.dialog.close();
        this.refreshData();
        this.$message({
          type: "success",
          message: "修改成功!"
        });
        this.refreshData();
      }, res =>{
        this.$message.error(res.data.msg);
      });
    },
    //新增提交
    dataAdd() {
      let Data = JSON.parse(JSON.stringify(this.userData));
      apiBase.DoService(Data, apiBase.getApiAdress().ChargeProject.UpdateAddRed, res => {
        this.$refs.dialog.close();
        this.refreshData();
        this.$message({
          type: "success",
          message: "新增成功!"
        });
      }, res =>{
        this.$message.error(res.data.msg);
      });
    },
    //详情
    dataInfo(id) {
      let data = {
        REDID: id
      };
       apiBase.DoService(data, apiBase.getApiAdress().ChargeProject.DetailRed, res => {
        this.userData = res.data.content;
      });
    },
    // 删除表格列
    dataDelete(id) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(callback => {
          let data = {
            REDID: id
          };
          apiBase.DoService(data, apiBase.getApiAdress().ChargeProject.UpdateDeleteRed , res => {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.refreshData();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
      },
      refreshData() {
      this.$emit("refreshData");
    },
      closeDialog() {
       this.$refs.dialog.close();
      },
   },
   components: {
       sweetModal
   }
 }
</script>

<style>

</style>
